package com.store.bookstore_backend.web.controller;

import com.store.bookstore_backend.dto.APIResponse;
import com.store.bookstore_backend.dto.ShopcarGetDTO;
import com.store.bookstore_backend.mapper.BookMapper;
import com.store.bookstore_backend.mapper.ShopcarMapper;
import com.store.bookstore_backend.service.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/shopCar")
public class ShopCarController {
    @Autowired
    ShopcarMapper shopcarMapper;
    @Autowired
    BookMapper bookMapper;
    @Autowired
    ShopCarService shopCarService;

    @GetMapping("/")
    public APIResponse<List<ShopcarGetDTO>> getShopCars(HttpServletRequest request) {
        return APIResponse.success(shopCarService.getShopCars(request));
    }

    @DeleteMapping("/")
    public APIResponse<Object> deleteShopCar(@RequestBody ArrayList<Integer> idList) {
        shopCarService.deleteShopCar(idList);
        return APIResponse.success();
    }

    @PostMapping("/{id}")
    public APIResponse<Object> updateShopCar(@PathVariable Integer id, Integer num,HttpServletRequest request) {
//        System.out.println(num);
        shopCarService.updateShopCar(id, request,num);
        return APIResponse.success();
    }

    @PutMapping("/{id}/{num}")
    public APIResponse<Object> updateShopCarNum(@PathVariable Integer id, @PathVariable Integer num, HttpServletRequest request) {
        shopCarService.updateShopCarNum(id, num, request);
        return APIResponse.success();
    }
}